from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-30 14:14:51.377434
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 30, Sep, 2022
Time: 14:14:56
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.5561
Nobs: 795.000 HQIC: -50.8822
Log likelihood: 10244.1 FPE: 6.51254e-23
AIC: -51.0857 Det(Omega_mle): 5.81958e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299188 0.053188 5.625 0.000
L1.Burgenland 0.108883 0.035695 3.050 0.002
L1.Kärnten -0.106473 0.018988 -5.607 0.000
L1.Niederösterreich 0.208184 0.074589 2.791 0.005
L1.Oberösterreich 0.102522 0.071644 1.431 0.152
L1.Salzburg 0.251874 0.038057 6.618 0.000
L1.Steiermark 0.037586 0.049786 0.755 0.450
L1.Tirol 0.106428 0.040348 2.638 0.008
L1.Vorarlberg -0.059021 0.034691 -1.701 0.089
L1.Wien 0.055203 0.064003 0.863 0.388
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063032 0.110237 0.572 0.567
L1.Burgenland -0.033227 0.073982 -0.449 0.653
L1.Kärnten 0.047785 0.039355 1.214 0.225
L1.Niederösterreich -0.171161 0.154592 -1.107 0.268
L1.Oberösterreich 0.384351 0.148489 2.588 0.010
L1.Salzburg 0.287881 0.078877 3.650 0.000
L1.Steiermark 0.106534 0.103187 1.032 0.302
L1.Tirol 0.313670 0.083624 3.751 0.000
L1.Vorarlberg 0.025064 0.071900 0.349 0.727
L1.Wien -0.017217 0.132651 -0.130 0.897
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190094 0.027337 6.954 0.000
L1.Burgenland 0.089822 0.018346 4.896 0.000
L1.Kärnten -0.008454 0.009759 -0.866 0.386
L1.Niederösterreich 0.263764 0.038336 6.880 0.000
L1.Oberösterreich 0.126713 0.036823 3.441 0.001
L1.Salzburg 0.047713 0.019560 2.439 0.015
L1.Steiermark 0.017090 0.025588 0.668 0.504
L1.Tirol 0.094134 0.020737 4.539 0.000
L1.Vorarlberg 0.059320 0.017830 3.327 0.001
L1.Wien 0.120847 0.032895 3.674 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108424 0.027985 3.874 0.000
L1.Burgenland 0.044657 0.018781 2.378 0.017
L1.Kärnten -0.016106 0.009991 -1.612 0.107
L1.Niederösterreich 0.193664 0.039245 4.935 0.000
L1.Oberösterreich 0.293416 0.037696 7.784 0.000
L1.Salzburg 0.115298 0.020024 5.758 0.000
L1.Steiermark 0.100389 0.026196 3.832 0.000
L1.Tirol 0.116182 0.021229 5.473 0.000
L1.Vorarlberg 0.070833 0.018253 3.881 0.000
L1.Wien -0.027018 0.033675 -0.802 0.422
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128966 0.050744 2.542 0.011
L1.Burgenland -0.051655 0.034055 -1.517 0.129
L1.Kärnten -0.040180 0.018116 -2.218 0.027
L1.Niederösterreich 0.170748 0.071161 2.399 0.016
L1.Oberösterreich 0.138554 0.068352 2.027 0.043
L1.Salzburg 0.286010 0.036309 7.877 0.000
L1.Steiermark 0.034620 0.047499 0.729 0.466
L1.Tirol 0.163719 0.038494 4.253 0.000
L1.Vorarlberg 0.103986 0.033097 3.142 0.002
L1.Wien 0.067547 0.061062 1.106 0.269
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059845 0.040252 1.487 0.137
L1.Burgenland 0.038558 0.027014 1.427 0.153
L1.Kärnten 0.050601 0.014370 3.521 0.000
L1.Niederösterreich 0.225289 0.056448 3.991 0.000
L1.Oberösterreich 0.281711 0.054220 5.196 0.000
L1.Salzburg 0.050917 0.028802 1.768 0.077
L1.Steiermark -0.006542 0.037678 -0.174 0.862
L1.Tirol 0.149909 0.030535 4.909 0.000
L1.Vorarlberg 0.071265 0.026254 2.714 0.007
L1.Wien 0.079399 0.048437 1.639 0.101
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178607 0.048122 3.712 0.000
L1.Burgenland -0.006038 0.032296 -0.187 0.852
L1.Kärnten -0.061120 0.017180 -3.558 0.000
L1.Niederösterreich -0.083519 0.067485 -1.238 0.216
L1.Oberösterreich 0.192296 0.064821 2.967 0.003
L1.Salzburg 0.056926 0.034433 1.653 0.098
L1.Steiermark 0.231084 0.045045 5.130 0.000
L1.Tirol 0.493625 0.036505 13.522 0.000
L1.Vorarlberg 0.049646 0.031387 1.582 0.114
L1.Wien -0.049139 0.057907 -0.849 0.396
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160647 0.055255 2.907 0.004
L1.Burgenland -0.011286 0.037083 -0.304 0.761
L1.Kärnten 0.065979 0.019726 3.345 0.001
L1.Niederösterreich 0.201288 0.077487 2.598 0.009
L1.Oberösterreich -0.061387 0.074429 -0.825 0.409
L1.Salzburg 0.215558 0.039536 5.452 0.000
L1.Steiermark 0.114159 0.051721 2.207 0.027
L1.Tirol 0.076704 0.041916 1.830 0.067
L1.Vorarlberg 0.124446 0.036039 3.453 0.001
L1.Wien 0.116106 0.066490 1.746 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.355174 0.032106 11.063 0.000
L1.Burgenland 0.006911 0.021547 0.321 0.748
L1.Kärnten -0.023584 0.011462 -2.058 0.040
L1.Niederösterreich 0.223269 0.045024 4.959 0.000
L1.Oberösterreich 0.176081 0.043246 4.072 0.000
L1.Salzburg 0.047095 0.022972 2.050 0.040
L1.Steiermark -0.018739 0.030052 -0.624 0.533
L1.Tirol 0.108790 0.024355 4.467 0.000
L1.Vorarlberg 0.073312 0.020940 3.501 0.000
L1.Wien 0.052918 0.038634 1.370 0.171
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041175 0.152528 0.191570 0.157484 0.125230 0.113969 0.066058 0.224754
Kärnten 0.041175 1.000000 -0.002641 0.129598 0.041360 0.096121 0.429746 -0.053244 0.101699
Niederösterreich 0.152528 -0.002641 1.000000 0.337362 0.154830 0.300516 0.110557 0.183720 0.326888
Oberösterreich 0.191570 0.129598 0.337362 1.000000 0.232255 0.333445 0.172616 0.172226 0.264535
Salzburg 0.157484 0.041360 0.154830 0.232255 1.000000 0.146160 0.126516 0.149072 0.136652
Steiermark 0.125230 0.096121 0.300516 0.333445 0.146160 1.000000 0.152899 0.140677 0.080880
Tirol 0.113969 0.429746 0.110557 0.172616 0.126516 0.152899 1.000000 0.114542 0.154938
Vorarlberg 0.066058 -0.053244 0.183720 0.172226 0.149072 0.140677 0.114542 1.000000 0.007257
Wien 0.224754 0.101699 0.326888 0.264535 0.136652 0.080880 0.154938 0.007257 1.000000